<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>评价管理</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<meta name="apple-mobile-web-app-status-bar-style" content="black">
	<meta name="apple-mobile-web-app-capable" content="yes">
	<meta name="format-detection" content="telephone=no">
	<link rel="stylesheet" href="/assets/layui-v2.5.5/css/layui.css" media="all" />
</head>
<body>
<br/>
<table class="layui-hide" id="test" lay-filter="test" ></table>
<script type="text/html" id="toolbarDemo">
<button class="layui-btn layui-btn-sm" lay-event="add"><i class="layui-icon">&#xe654;</i>添加</button>
</script>
<script type="text/html" id="barDemo">
<a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
<a class="layui-btn layui-btn-xs" lay-event="check">审核</a>
</script>    
<script src="/assets/layui-v2.5.5/layui.js" charset="utf-8"></script> 
<script>
var $,id,table;
	layui.use(['table','jquery'], function(){
	  table = layui.table;
	  $ = layui.$;
	  id='#(id)';
	  searchTable();
	  //监听头工具栏事件
	  table.on('toolbar(test)', function(obj){
	  var checkStatus = table.checkStatus(obj.config.id);
	  switch(obj.event){
	    case 'add':
	    	layer.open({
                type: 2,
                title: '添加评论',
                content:['/teacher/commentAdd?id='+id] ,//允许出现滚动条
                area:['70%', '50%']
            });   
	    break;
	  };
	});
	//监听行工具事件
	  table.on('tool(test)', function(obj){ //注：tool 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
	    var data = obj.data //获得当前行数据
	    ,layEvent = obj.event; //获得 lay-event 对应的值
	    if(layEvent === 'del'){
   				layer.confirm('确定要进行此删除操作吗?', function(index){
   			        layer.close(index);	        
   			        $.ajax({
   			    	    url : '/teacher/commentDel',
   			    		type : "post",
   			    		data : {id:data.id},
   			    		dataType : "json",
   			    		success : function(ret) {
   			    			if (ret.state == 'ok') {
   			    				layer.msg(ret.msg, {icon: 1, offset: '15px', time: 600}, function(){
   			    					var index = parent.layer.getFrameIndex(window.name);
   			    					layer.close(index);
   			    					$(".layui-laypage-btn").click();
   			    				});
   			    			} else {
   			    				layer.msg(ret.msg, {icon: 2, offset: '10px'});
   			    			}
   			    		},
   			    		error: function() {
   			          } 
   			      });
   			   });				      
	    }else if(layEvent === 'check'){
				layer.open({
                type: 2,
                title: '审核',
                content:['/teacher/commentCheck?id='+data.id] ,
                area:['400px', '250px']
        	}); 		 	    			
	   }
	  });
	});
	function searchTable(){
		table.render({
		    elem: '#test'
		    ,url:'/teacher/commentPaginate'
	    	,where: {id: id} 
			,toolbar: '#toolbarDemo'
		    ,title: '师资评价'
		    ,cols: [[
		    	  {type:'numbers', title:'ID', width:'10%', fixed: 'left', unresize: true}
			     ,{field:'commentValue', title:'评价内容', width:'30%'}
			     ,{field:'createAt', title:'评价时间', width:'20%'}	
			     ,{field:'isCheck', title:'审核状态', width:'20%'}	
			     ,{fixed: '', title:'操作', toolbar: '#barDemo', width:'20%'}
		    ]]
		    ,page: true
		    ,request: {     
		        pageName: 'pageNumber' //页码的参数名称，默认：page
		        ,limitName: 'pageSize' //每页数据量的参数名，默认：limit
		    }
		  });
	}
</script> 
</body>
</html>